var t = getApp(), e = Date.now();

Page({
    data: {
        dataNows: e,
        mock: [],
        panelIndex: 0,
        zhaosCut: "1",
        shareShow: !1,
        showEarnings: !1,
        page: 1,
        status: !1,
        commission_name: "",
        showTime: !1,
        currentShowTime: "",
        currentDate: new Date().getTime(),
        minDate: new Date(2010, 0, 1).getTime(),
        maxDate: new Date().getTime(),
        formatter: function(t, e) {
            return "".concat(e, "year" === t ? "年" : "月");
        }
    },
    onLoad: function(e) {
        if (e.scene) {
            var a = decodeURIComponent(e.scene);
            if (a) {
                var i = [];
                i = a.split(",");
                for (var n = 0; n < i.length; n++) {
                    var o;
                    "ind" == (o = i[n].split("="))[0] ? (console.log(o[1]), this.setData({
                        panelIndex: o[1]
                    })) : "type" == o[0] ? console.log(o[1]) : "mid" == o[0] && t._setMid(o[1]);
                }
            }
        }
        this.getdata(this.data.panelIndex), this.setData({
            currentShowTime: this.timestampToTime(new Date())
        });
    },
    Earnings: function() {
        this.setData({
            showEarnings: !0
        });
    },
    goWd: function() {
        wx.navigateTo({
            url: "/packageC/microshop/microShop_home/microShop_home"
        });
    },
    tapCut: function(t) {
        console.log(t);
        var e = t.currentTarget.dataset.ind;
        this.setData({
            zhaosCut: e
        }), console.log(this.data.zhaosCut), "1" == e ? (this.setData({
            title: "staffLevel"
        }), this.inData("staffLevel")) : "2" == e && (this.setData({
            title: "merchantLevel"
        }), this.inData("merchantLevel"));
    },
    apply: function(t) {
        if (this.data.title) switch (console.log(this.data.title), this.data.title) {
          case "commission":
            wx.navigateTo({
                url: "/packageA/member/extension/ExtensionApply/ExtensionApply"
            });
            break;

          case "areaDividend":
            wx.navigateTo({
                url: "/packageB/member/income/applyRegionalAgency/applyRegionalAgency"
            });
            break;

          case "teamDividend":
            wx.navigateTo({
                url: "/packageA/member/extension/ExtensionApply/ExtensionApply"
            });
            break;

          case "micro":
            wx.navigateTo({
                url: "/packageC/microshop/microShop_apply/microShop_apply"
            });
            break;

          case "staffLevel":
            wx.navigateTo({
                url: "/packageB/member/enterprise/enterprise_apply/enterprise_apply"
            });
            break;

          case "merchantLevel":
            wx.navigateTo({
                url: "/packageB/member/enterprise/enterprose_center_apply/enterprose_center_apply"
            });
            break;

          case "room":
            wx.navigateTo({
                url: "/packageD/directSeeding/anchorApply/anchorApply"
            });
        }
    },
    goDetail: function(t) {
        if (this.data.title) switch (console.log(this.data.title), this.data.title) {
          case "commission":
            wx.navigateTo({
                url: "/packageA/member/distribution/distribution"
            });
            break;

          case "areaDividend":
            wx.navigateTo({
                url: "/packageB/member/income/regionalAgencyCenter/regionalAgencyCenter"
            });
            break;

          case "teamDividend":
            wx.navigateTo({
                url: "/packageB/member/income/teamAgentCenter/teamAgentCenter"
            });
            break;

          case "staffLevel":
            wx.navigateTo({
                url: "/packageB/member/enterprise/enterprise_index/enterprise_index"
            });
            break;

          case "room":
            wx.navigateTo({
                url: "/packageD/directSeeding/liveDividend/liveDividend"
            });
        }
    },
    goTx: function() {
        wx.navigateTo({
            url: "/packageA/member/withdrawal/withdrawal"
        });
    },
    chooseTabData: function(t) {
        console.log(t);
        var e, a = t.detail.index, i = t.detail.title;
        this.setData({
            panelIndex: a,
            page: 1,
            isCut: ""
        }), i == this.data.commission_title ? e = "commission" : i == this.data.team_dividend_title ? e = "teamDividend" : "招商" == i ? 1 == this.data.zhaosCut ? e = "staffLevel" : 2 == this.data.zhaosCut && (e = "merchantLevel") : i == this.data.micro_title ? e = "micro" : i == this.data.area_dividend_title ? e = "areaDividend" : i == this.data.room_title ? e = "room" : i == this.data.income_title && (e = "income"), 
        this.setData({
            title: e
        }), console.log(e), this.inData(e);
    },
    showTap: function(e) {
        console.log(e), console.log(this.data.title), this.setData({
            shareShow: !0
        }), wx.showLoading({
            title: "海报加载中"
        });
        var a = this, i = t.getNetAddresss("plugin.ranking.api.poster.generateGoodsPoster");
        t._getNetWork({
            url: i,
            data: {
                getSwitch: "getSwitch",
                plugin_type: a.data.title,
                id: a.data.panelIndex
            },
            success: function(t) {
                var e = t.data;
                console.log(e), 1 == e.result ? (a.setData({
                    image_url: e.data.image_url
                }), wx.hideLoading({
                    complete: function(t) {}
                })) : (wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                }), wx.hideLoading({
                    complete: function(t) {}
                }));
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    couponclose: function() {
        this.setData({
            shareShow: !1,
            showEarnings: !1
        });
    },
    goHome: function() {
        wx.reLaunch({
            url: "/packageG/index/index"
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        if (console.log(this.data.current_page, this.data.last_page), !(this.data.current_page >= this.data.last_page)) {
            var t = this.data.page + 1;
            this.setData({
                page: t
            }), this.inDataMore(this.data.title);
        }
    },
    onShareAppMessage: function() {},
    onShareTimeline: function() {},
    getdata: function(e) {
        var a = this, i = t.getNetAddresss("plugin.ranking.api.index.index");
        t._getNetWork({
            url: i,
            success: function(t) {
                var i = t.data;
                if (console.log(i), 1 == i.result) {
                    a.setData({
                        commission: i.data.getSet.commission,
                        merchantLevel: i.data.getSet.merchantLevel,
                        micro: i.data.getSet.micro,
                        staffLevel: i.data.getSet.staffLevel,
                        team_dividend: i.data.getSet.team_dividend,
                        area_dividend: i.data.getSet.area_dividend,
                        room: i.data.getSet.room,
                        getSet: i.data.getSet,
                        commission_title: i.data.getSet.commission_title,
                        merchantLevel_title: i.data.getSet.merchantLevel_title,
                        staffLevel_title: i.data.getSet.staffLevel_title,
                        micro_title: i.data.getSet.micro_title,
                        team_dividend_title: i.data.getSet.team_dividend_title,
                        area_dividend_title: i.data.getSet.area_dividend_title,
                        room_title: i.data.getSet.room_title,
                        income_title: i.data.getSet.income_title,
                        thumb: i.data.getSet.thumb,
                        txTitle: i.data.getSet.title,
                        commission_name: i.data.getSet.commission_order
                    });
                    var n, o = [];
                    i.data.getSet.commission_title && o.push(i.data.getSet.commission_title), i.data.getSet.micro_title && o.push(i.data.getSet.micro_title), 
                    i.data.getSet.team_dividend_title && o.push(i.data.getSet.team_dividend_title), 
                    i.data.getSet.area_dividend_title && o.push(i.data.getSet.area_dividend_title), 
                    i.data.getSet.room_title && o.push(i.data.getSet.room_title), (i.data.getSet.merchantLevel_title || i.data.getSet.staffLevel_title) && o.push(i.data.getSet.merchantLevel_title || i.data.getSet.staffLevel_title ? "招商" : ""), 
                    i.data.getSet.income_title && o.push(i.data.getSet.income_title), a.setData({
                        mock: o
                    }), o[e] == i.data.getSet.commission_title ? n = "commission" : o[e] == i.data.getSet.team_dividend_title ? n = "teamDividend" : "招商" == o[e] ? 1 == a.data.zhaosCut ? n = "staffLevel" : 2 == a.data.zhaosCut && (n = "merchantLevel") : o[e] == i.data.getSet.micro_title ? n = "micro" : o[e] == i.data.getSet.area_dividend_title ? n = "areaDividend" : o[e] == i.data.getSet.room_title ? n = "room" : o[e] == i.data.getSet.income_title && (n = "income"), 
                    a.setData({
                        title: n
                    }), a.inData(n);
                } else wx.showToast({
                    icon: "none",
                    title: i.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    inData: function(e) {
        wx.showLoading({
            title: "加载中"
        });
        var a = {
            getSwitch: "getSwitch",
            plugin_type: e
        };
        "income" == e && (a = {
            getSwitch: 1,
            plugin_type: e,
            create_month: this.data.currentShowTime.split("-")[0] + this.data.currentShowTime.split("-")[1]
        });
        var i = this, n = t.getNetAddresss("plugin.ranking.api.index.index");
        t._getNetWork({
            url: n,
            data: a,
            success: function(e) {
                var a = e.data;
                console.log(a), 1 == a.result ? (i.setData({
                    list: a.data.getSwitch
                }), t._isTextEmpty(a.data.getSwitch) || ("1" == a.data.getSwitch.status ? i.setData({
                    status: !0,
                    errText: a.data.getSwitch.text
                }) : i.setData({
                    current_page: a.data.getSwitch.rankingCommission.current_page,
                    last_page: a.data.getSwitch.rankingCommission.last_page,
                    status: !1
                })), wx.hideLoading({
                    complete: function(t) {}
                })) : (wx.showToast({
                    icon: "none",
                    title: a.msg,
                    duration: 1500
                }), wx.hideLoading({
                    complete: function(t) {}
                }));
            },
            fail: function(t) {
                console.log(t), wx.hideLoading({
                    complete: function(t) {}
                });
            }
        });
    },
    inDataMore: function(e) {
        var a = {
            getSwitch: "getSwitch",
            plugin_type: e,
            page: this.data.page
        };
        "income" == e && (a = {
            getSwitch: 1,
            plugin_type: e,
            create_month: this.data.currentShowTime.split("-")[0] + this.data.currentShowTime.split("-")[1],
            page: this.data.page
        }), wx.showLoading({
            title: "加载中"
        });
        var i = this, n = t.getNetAddresss("plugin.ranking.api.index.index");
        t._getNetWork({
            url: n,
            data: a,
            success: function(e) {
                var a = e.data;
                1 == a.result ? (i.setData({
                    "list.rankingCommission.data": i.data.list.rankingCommission.data.concat(a.data.getSwitch.rankingCommission.data)
                }), t._isTextEmpty(a.data.getSwitch) || i.setData({
                    current_page: a.data.getSwitch.rankingCommission.current_page,
                    last_page: a.data.getSwitch.rankingCommission.last_page
                }), wx.hideLoading({
                    complete: function(t) {}
                })) : (wx.showToast({
                    icon: "none",
                    title: a.msg,
                    duration: 1500
                }), wx.hideLoading({
                    complete: function(t) {}
                }));
            },
            fail: function(t) {
                console.log(t), wx.hideLoading({
                    complete: function(t) {}
                });
            }
        });
    },
    saveImg: function() {
        wx.getSetting({
            success: function(t) {
                t.authSetting["scope.writePhotosAlbum"] || wx.authorize({
                    scope: "scope.writePhotosAlbum",
                    success: function() {
                        console.log("授权成功");
                    }
                });
            }
        });
        var t = this.data.image_url;
        wx.downloadFile({
            url: t,
            success: function(t) {
                console.log(t), wx.saveImageToPhotosAlbum({
                    filePath: t.tempFilePath,
                    success: function(t) {
                        wx.showToast({
                            title: "保存成功",
                            icon: "none",
                            duration: 2e3
                        });
                    },
                    fail: function(t) {
                        console.log(t), "saveImageToPhotosAlbum:fail auth deny" === t.errMsg && (console.log("当初用户拒绝，再次发起授权"), 
                        wx.openSetting({
                            success: function(t) {
                                t.authSetting["scope.writePhotosAlbum"] ? wx.showToast({
                                    icon: "none",
                                    title: "获取权限成功,再次长按保存图片",
                                    duration: 1500
                                }) : wx.showToast({
                                    icon: "none",
                                    title: "获取权限失败,保存图片需要用户授权",
                                    duration: 1500
                                });
                            }
                        }));
                    },
                    complete: function(t) {
                        console.log(t);
                    }
                });
            }
        });
    },
    timestampToTime: function(t) {
        var e = new Date(t), a = e.getFullYear() + "-", i = e.getMonth() + 1 < 10 ? "0" + (e.getMonth() + 1) : e.getMonth() + 1;
        this.change(e.getDate());
        return a + i;
    },
    change: function(t) {
        return t < 10 ? "0" + t : t;
    },
    searchTime: function() {
        this.setData({
            showTime: !0
        });
    },
    confirmTime: function(t) {
        this.setData({
            showTime: !1,
            currentShowTime: this.timestampToTime(this.data.currentDate)
        }), this.inData("income");
    },
    onInput: function(t) {
        this.setData({
            currentDate: t.detail
        });
    },
    cancelTime: function() {
        this.setData({
            showTime: !1
        });
    }
});